//
//  ViewController.m
//  JFTRequest
//
//  Created by 竣付通 on 2017/11/6.
//  Copyright © 2017年 junHaoPay. All rights reserved.
//

#import "ViewController.h"
#import "JFTRequest.h"
#import "MBProgressHUD.h"
#import "HLMBProgressHUD.h"
#import "JFTDES.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *uploadImageView;
@property (weak, nonatomic) IBOutlet UIImageView *downloadImageView;
@end

@implementation ViewController
- (IBAction)getDataRequest:(UIButton *)sender {
    [[JFTRequest requestManager] getDataWithUrl:[@"http://software.jtpay.com:8080/" stringByAppendingString:@"jh-web-softwareManager/mobile/getServerTime"] WithParameters:nil Sucessfil:^(id returnData) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSTimeInterval serviceStamp =[(NSString *)returnData doubleValue];
            NSLog(@"%f",serviceStamp);
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            [HLMBProgressHUD addMBProgressHUDinView:self.view hudMode:5 hideDelay:2 hudDetailText:@"校准成功"];
        });
    } failure:^(id failerObjc) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            [HLMBProgressHUD addMBProgressHUDinView:self.view hudMode:5 hideDelay:2 hudDetailText:@"请检查网络连接！"];
        });
        
    } error:^(NSError *err) {
        if (err) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [MBProgressHUD hideHUDForView:self.view animated:YES];
                [HLMBProgressHUD addMBProgressHUDinView:self.view hudMode:5 hideDelay:2 hudDetailText:@"校准失败"];
            });
            return ;
        }
    }];
}

- (IBAction)postDataRequest:(UIButton *)sender {
    NSString *userPwd = [JFTDES md532BitLower:@"appletest"];
    [HLMBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *dic=@{@"systemName":@"JFT",@"subType":@"wallet",@"userAccount":@"appletest",@"userPwd":userPwd};
    NSString *noncer = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970]];
    NSString *UrlString = @"http://software.jtpay.com:8080/jh-web-softwareManager/mobile/checkAccountAndPws";
    [[JFTRequest requestManager] postDataWithUrl:UrlString WithParameters:dic WithNoncer:noncer Sucessfil:^(id returnData) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [HLMBProgressHUD hideHUDForView:self.view animated:YES];
        });
        NSLog(@"%@",returnData);
    } failure:^(id failerObjc) {
        return ;
    } error:^(NSError *err) {
        return ;
    }];
}

- (IBAction)Upload:(UIButton *)sender {
    UIImage *image = [UIImage imageNamed:@"logo"];
    NSURL *url = [NSURL URLWithString:@""];
    [[JFTRequest requestManager] loadImageWithUrl:url andImage:image Sucessfil:^(id returnData) {
        
    } failure:^(id failerObjc) {
        return ;
    } error:^(NSError *err) {
        return ;
    }];
}

- (IBAction)download:(UIButton *)sender {
    NSString *urlStr = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510044031006&di=bfd9d0b49dab7383bc7dd95ac16842d7&imgtype=0&src=http%3A%2F%2Fa2.att.hudong.com%2F40%2F64%2F20300544057222148670648444437.jpg";
    NSURL *url = [NSURL URLWithString:urlStr];
    [[JFTRequest requestManager] downloadImageWithUrl:url Sucessfil:^(id returnData) {
        UIImage *image = (UIImage *)returnData;
        dispatch_async(dispatch_get_main_queue(), ^{
        self.downloadImageView.image = image;
        });
        
    } failure:^(id failerObjc) {
         return ;
    } error:^(NSError *err) {
         return ;
    }];
}

@end
